#pragma once
#include "../im.h"
#include "IMSession.h"

class IMUser;

class IMUser
{
public:
    struct Team
    {
        uint8_t team_id;
        // 分组名称
        std::string name;
    };

    struct Friend
    {
        std::string teamName;
        std::string mackName;
        uint8_t teamId;
        std::shared_ptr<IMUser> user;
    };

public:
    IMUser();
    IMUser(const userid_t &uid, const std::string &username, const std::string &nickname, const online_type &status, const IMSessionPtr &session);

private:
    userid_t uid_;
    std::string username_;
    std::string nickname_;
    std::string password_;
    online_type status_;
    IMSessionPtr session_;
    // std::vector<userid_t> friends_;
    // 分组 0 默认分组 0不能删除 255 黑名单
    std::map<std::string, uint8_t> teams_id_;
    std::map<uint8_t, std::string> teams_name_;
    // 群组
    std::vector<groupid_t> groups_;

    std::vector<Friend> friends_;

public:
    userid_t getUid() const { return uid_; }
    std::string getUsername() const { return username_; }
    std::string getNickname() const { return nickname_; }
    std::string getPassword() const { return password_; }
    online_type getStatus() const { return status_; }
    IMSessionPtr getSession() const { return session_; }
    std::string getTeamName(const uint8_t &team_id) const { return teams_name_.at(team_id); }
    std::map<uint8_t, std::string> getTeams() const { return teams_name_; }
    std::vector<Friend> getFriends() const { return friends_; }

    void send(const msg_type &t, const char *data, const size_t &len);

    void iniTeam(boost::property_tree::ptree &pt);
    bool addTeam(const std::string &name);
    bool delTeam(const std::string &name);
    bool isFriend(const userid_t &uid);
    bool isFriend(const std::string &username);
    // 移动好友到其他分组
    bool moveFriend(const userid_t &uid, const std::string &team_name);
    // 添加好友
    void addFriend(const userid_t &uid);
    void addFriend(const userid_t &uid, const std::string &team_name);
    void removeFriend(const userid_t &uid);

    void addGroup(const groupid_t &gid);
    void removeGroup(const groupid_t &gid);

    void dbAddGroup(const groupid_t &gid);
};

typedef std::shared_ptr<IMUser> IMUserPtr;